package com.gxuwz.hmr.project.system.agriculture.controller;

import java.util.List;

import com.gxuwz.hmr.project.system.agriculture.domain.Agriculture;
import com.gxuwz.hmr.project.system.agriculture.service.IAgricultureService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.agriculture.domain.Agriculture;
import com.ruoyi.project.system.agriculture.service.IAgricultureService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 农合经办信息Controller
 * 
 * @author ruoyi
 * @date 2021-05-05
 */
@Controller
@RequestMapping("/system/agriculture")
public class AgricultureController extends BaseController
{
    private String prefix = "system/agriculture";

    @Autowired
    private IAgricultureService agricultureService;

    @RequiresPermissions("system:agriculture:view")
    @GetMapping()
    public String agriculture()
    {
        return prefix + "/agriculture";
    }

    /**
     * 查询农合经办信息列表
     */
    @RequiresPermissions("system:agriculture:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Agriculture agriculture)
    {
        startPage();
        List<Agriculture> list = agricultureService.selectAgricultureList(agriculture);
        return getDataTable(list);
    }

    /**
     * 导出农合经办信息列表
     */
    @RequiresPermissions("system:agriculture:export")
    @Log(title = "农合经办信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Agriculture agriculture)
    {
        List<Agriculture> list = agricultureService.selectAgricultureList(agriculture);
        ExcelUtil<Agriculture> util = new ExcelUtil<Agriculture>(Agriculture.class);
        return util.exportExcel(list, "农合经办信息数据");
    }

    /**
     * 新增农合经办信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存农合经办信息
     */
    @RequiresPermissions("system:agriculture:add")
    @Log(title = "农合经办信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Agriculture agriculture)
    {
        return toAjax(agricultureService.insertAgriculture(agriculture));
    }

    /**
     * 修改农合经办信息
     */
    @GetMapping("/edit/{agrId}")
    public String edit(@PathVariable("agrId") Long agrId, ModelMap mmap)
    {
        Agriculture agriculture = agricultureService.selectAgricultureById(agrId);
        mmap.put("agriculture", agriculture);
        return prefix + "/edit";
    }

    /**
     * 修改保存农合经办信息
     */
    @RequiresPermissions("system:agriculture:edit")
    @Log(title = "农合经办信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Agriculture agriculture)
    {
        return toAjax(agricultureService.updateAgriculture(agriculture));
    }

    /**
     * 删除农合经办信息
     */
    @RequiresPermissions("system:agriculture:remove")
    @Log(title = "农合经办信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(agricultureService.deleteAgricultureByIds(ids));
    }
}
